package com.sks.web.action.house;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.stereotype.Controller;

import com.sks.bean.PageView;
import com.sks.bean.QueryResult;
import com.sks.bean.pojo.AuditHistory;
import com.sks.service.house.AuditHistoryService;
import com.sks.utils.StringUtil;
import com.sks.web.action.BasicAction;
import com.sks.web.formbean.house.AuditHistoryForm;

@Controller("/cms/auditHistory")
public class AuditHistoryAction extends BasicAction {
	@Resource(name = "auditHistoryServiceBean") private AuditHistoryService service;
	
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		AuditHistoryForm formbean = (AuditHistoryForm) form;
		
		PageView<AuditHistory> pageView = new PageView<AuditHistory>(12, formbean.getPage());
		List<Object> params = new ArrayList<Object>();
		StringBuffer jpql = new StringBuffer(" 1 = 1 ");
		
		if (!StringUtil.isEmpty(formbean.getUsername())) {
			jpql.append(" and o.employee.username = ?");
			params.add(formbean.getUsername());
		}
		
		if (!StringUtil.isEmpty(formbean.getObjType())) {
			jpql.append(" and o.objType = ?");
			params.add(formbean.getObjType());
		}
		
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		orderby.put("ts", "desc");
		
		QueryResult<AuditHistory> qr = service.getScrollData(pageView.getFirstResult(), pageView
				.getMaxresult(), jpql.toString(), params.toArray(), orderby);
		pageView.setQueryResult(qr);
		request.setAttribute(PAGEVIEW, pageView);
		return mapping.findForward(LIST);
	}
	
	public ActionForward top(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		request.setAttribute("auditHistoryCount", service.getCountByDate(new Date()));
		return mapping.findForward("top");
	}

	/**
	 * 支付方式删除
	
	@Permission(module = "info", privilege = "update")
	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		PayTypeForm formbean = (PayTypeForm) form;
		service.delete(formbean.getPayTypeId());
		request.setAttribute(MESSAGE, getMessage("display.delete") + getMessage("info.payType") + getMessage("display.success"));
		request.setAttribute("urladdress", SiteUrl
				.readUrl("com.sks.web.action.house.payType"));
		return mapping.findForward(MESSAGE);
	}
	 */
}
